ShinyBaseball is an R package containing several Shiny apps to illustrate Statcast baseball data. The package can be used to understand how pitch outcomes vary by pitch type and location for a specific pitcher or a specific hitter. One can see how the location of pitches depend on the pitch type and the count. Also, by visualizing the location of in-play events, one can see the hot and cold regions for specific hitters. Statcast data from the 2019 season is included with the package.
This document provides an overview with snapshots of the Shiny functions available in ShinyBaseball version 0.2.7.
This package depends on the following packages that should be installed first.
shiny, ggplot2, dplyr, stringr, tidyr
To install the ShinyBaseball package, use the install_github() function from the remotes package:
library(remotes)
install_github("bayesball/ShinyBaseball")
There are several apps demonstrating some interactive graphics features of Shiny.
This app illustrates scatterplot brushing. One can select X and Y variables to graph. One selects a region of interest and the app will display the names, x and y variables for the points in the region.
PointBrush()
These apps illustrating clicking and hovering capabilities of Shiny graphics. Again one selects variables to graph. By clicking or hovering near a point, the app will display the name and X and Y variables for that point.
PointClick()
This is useful for exploring relationships between four variables in the FanGraphs batting leaderboard. One selects X1, Y1, X2, Y2 variables to graph. One sees two scatterplots. One can brush either scatterplot - the corresponding points in the other scatterplot are colored red. Also the app displays the names and variables corresponding to the points in the brushed region.
FourMeasures()
This app is helpful for visualizing pitch outcomes for any pitcher or batter of interest.
We indicate by use of the Player Type button if we want to look at pitching or batting data. Then we enter in the Player Name and the Pitch Type of interest.
Here we indicate that we wish to look at a Pitcher, enter in Jacob DeGrom’s name, and select “FF” from the Pitch Type pallet.
We see the locations of All of Jacob DeGrom’s four-seamers where the color of the point corresponds to the Type variable (ball, strike, or inplay).
PitchOutcome()
By selecting “Called” from the Pitches to Display pallet, we see the locations of all Called pitches where the color corresponds to called ball or called strike.
By selecting “Swing” from the Pitches to Display pallet, we see the locations of all swung pitches – the color of the point corresponds to the outcome (foul, inplay or miss). One can brush over this scatterplot – the app displays the number of swung pitches and miss rate for the points in the brushed region.
By selecting “In-Play” from the Pitches to Display pallet, we see the locations of all pitches put in-play – the color of the point corresponds to the outcome (hit or out). One can brush over this scatterplot – the app displays the number of pitches in-play and hit rate for the points in the brushed region.
This app is helpful for comparing pitch locations across pitch types and counts.
We enter in the Pitcher Name (here Jacob DeGrom). By selecting “FF” and “SL” from the Pitch Type pallet and “0-0” from the Count pallet, we can compare locations of four-seamers and sliders on a 0-0 count.
PitchTypeCount()
By selecting “FF” and “SL” from the Pitch Type pallet and “2-0”, “1-1” and “0-2” from the Count pallet, we can compare locations of four-seamers and sliders on these three “2 pitch” counts.
This app is a general function for plotting and brushing different measures on balls put in-play over the zone.
A live version of BrushingZone() can be found on the RStudio Shiny Server:
https://bayesball.shinyapps.io/BrushingZone/
We begin by entering in a batter’s name – here we enter Bryce Harper.
We see the locations of all pitches put in play where the color of the point corresponds to the launch speed.
BrushingZone()
If one clicks on an individual point, you will see the launch speed, launch angle and expected batting average for that ball put into play.
If one brushes over this plot, the app displays number of balls in play (BIP), the number of hits (H) and home runs (HR), and the average values of launch speed, hit rate, home run rate and expected BA for points in the brushed region.
If one selects Home Run, the points are colored by the outcome (home run or not).
This app can also be used to show locations of hits or expected batting average over the zone.
All of the data for using these apps is included as part of the ShinyBaseball package.
This provides the Statcast ids for all Major League Players.
This dataset contains stats for the FanGraphs leaders for the 2020 season. This data is used for the FourMeasures(), PointBrush(), PointClick(), PointHover() Shiny apps.
This dataset provides Statcast data for the 125,751 balls put in play for the 2019 season. This data is used for the BrushingZone() Shiny app.
This dataset provides Statcast data for the 732,473 pitches in the 2019 season. This is data is used for the PitchOutcome() and PitchTypeCount() Shiny apps.